<!--
 * new page
 * @author: YK
 * @since: 2023-11-29
 * index.vue
-->
<template>
  <div class="container">
    <el-button @click="handleClick(true)" type="primary"
      ><slot></slot
    ></el-button>
    <div class="m--choose-icon-dialog-body-height">
      <el-dialog :title="title" v-model="visibles" @close="handleClick(false)">
        <div class="container">
          <div
            class="item"
            v-for="(item, index) in Object.keys(ElIcons)"
            :key="index"
            @click="copy(item)"
          >
            <div><component :is="`el-icon${toLine(item)}`"></component></div>
            <div class="title">{{ item }}</div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as ElIcons from "@element-plus/icons-vue";
import { ref } from "vue";
import { toLine } from "../../../utils";
import { useCopy } from "../../../hooks/useCopy/index";
const props = withDefaults(
  defineProps<{
    title: string;
    visible: boolean;
  }>(),
  { title: "", visible: false } 
);
const visibles = ref<boolean>(props.visible);
const emits = defineEmits(["update:visible"]);
const handleClick = (b: boolean) => {
  emits("update:visible", b);
  visibles.value = b;
};
const copy = (text: string) => {
  useCopy(`<el-icon${toLine(text)}/>`);
  handleClick(false)
};
</script>

<style scoped lang="scss">
.container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  .item {
    width: 20%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    cursor: pointer;
    font-size: 14px;
    height: 70px;
  }
  .title {
    flex: 1;
  }
  svg {
    width: 1.5em;
    height: 1.5em;
  }
}
</style>
